package com.dff.jrfw;

import android.content.res.Configuration;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.dff.jrfw.dialog.LoadingDialog;
import com.dff.jrfw.utils.AppManager;
import com.dff.jrfw.utils.Util;
import com.gyf.immersionbar.ImmersionBar;

public class BaseActivity extends AppCompatActivity {


    private LoadingDialog mDialog;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImmersionBar.with(this).init();
        ImmersionBar.with(this)
                .statusBarColor(R.color.white)
                .statusBarDarkFont(true)
                .fitsSystemWindows(true)
                .init();
        AppManager.getAppManager().addActivity(this);
    }


    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // 如果你的app可以横竖屏切换，并且适配4.4或者emui3手机请务必在onConfigurationChanged方法里添加这句话
        ImmersionBar.with(this).init();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    public void showLoading() {
        if (mDialog == null) {
            mDialog = new LoadingDialog(this);
        }
        if (Util.scanForActivity(mDialog.getContext()) != null && !Util.scanForActivity(mDialog.getContext()).isFinishing() && !mDialog.isShowing()) {
            mDialog.show();
        }
    }


    public void hideLoading() {
        if (mDialog != null && Util.scanForActivity(mDialog.getContext()) != null && !Util.scanForActivity(mDialog.getContext()).isFinishing() && mDialog.isShowing()) {
            mDialog.dismiss();
        }

    }


}
